/*
 *    Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: lengleng (wangiegie@gmail.com)
 */

package com.pig4cloud.pigx.system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.common.log.annotation.SysLog;
import com.pig4cloud.pigx.system.dto.SystemPlatformAddDTO;
import com.pig4cloud.pigx.system.dto.SystemPlatformEditDTO;
import com.pig4cloud.pigx.system.entity.SystemPlatform;
import com.pig4cloud.pigx.system.service.SystemPlatformService;
import com.pig4cloud.pigx.system.vo.SystemPlatformOptionVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 平台
 *
 * @since 2022-11-23 15:15:20
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/platform")
@Api(value = "platform", tags = "平台管理")
public class SystemPlatformController {

	private final SystemPlatformService systemPlatformService;

	/**
	 * 分页查询
	 *
	 * @param page      分页条件
	 * @param condition 查询条件
	 * @return {@link R< Page< SystemPlatform>>}
	 * @since 2022/11/24 10:48
	 */
	@ApiOperation(value = "分页查询", notes = "分页查询")
	@GetMapping("/page")
	public R<Page<SystemPlatform>> page(Page<SystemPlatform> page, SystemPlatform condition) {
		return R.ok(systemPlatformService.page(page, condition));
	}

	/**
	 * 根据id查询详情
	 *
	 * @param id id
	 * @return {@link R< SystemPlatform>}
	 * @since 2022/11/24 11:21
	 */
	@ApiOperation(value = "通过id查询", notes = "通过id查询")
	@GetMapping("/{id}")
	public R<SystemPlatform> getById(@PathVariable("id") Long id) {
		return R.ok(systemPlatformService.getById(id));
	}

	/**
	 * 新增平台
	 *
	 * @param dto 数据
	 * @return {@link R< Object>}
	 * @since 2022/11/24 11:30
	 */
	@ApiOperation(value = "新增平台", notes = "新增平台")
	@SysLog("新增平台")
	@PostMapping
	public R<Object> add(@Validated @RequestBody SystemPlatformAddDTO dto) {
		systemPlatformService.add(dto);
		return R.ok();
	}

	/**
	 * 修改平台
	 *
	 * @param dto 数据
	 * @return {@link R< Object>}
	 * @since 2022/11/24 11:30
	 */
	@ApiOperation(value = "修改平台", notes = "修改平台")
	@SysLog("修改平台")
	@PutMapping
	public R<Object> edit(@Validated @RequestBody SystemPlatformEditDTO dto) {
		systemPlatformService.edit(dto);
		return R.ok();
	}

	/**
	 * 根据id逻辑删除
	 *
	 * @param id id
	 * @return {@link R< Object>}
	 * @since 2022/11/24 14:26
	 */
	@ApiOperation(value = "通过id删除平台", notes = "通过id删除平台")
	@SysLog("通过id删除平台")
	@DeleteMapping("/{id}")
	public R<Object> del(@PathVariable Long id) {
		systemPlatformService.del(id);
		return R.ok();
	}

	/**
	 * 查询选项数据
	 *
	 * @return {@link R< List< SystemPlatformOptionVO>}
	 * @since 2022/11/24 14:26
	 */
	@ApiOperation(value = "查询选项数据", notes = "查询选项数据")
	@GetMapping("/option")
	public R<List<SystemPlatformOptionVO>> option() {
		return R.ok(systemPlatformService.option());
	}
}
